﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RestTask : Task {

    private EventDelegate finishDelegate = null;
    public RestTask(TaskManager manager)
        : base(manager,TaskType.RestTask)
    {
        
    }

    public override void Start()
    {
        finishDelegate = new EventDelegate(OnClickFinish);

        base.Start();

        // 设计倒计时
        bool isSet = false;
        if (PlayerPrefs.HasKey(TestKey.NormalToSpecailRestTaskInterval))
        {
            var interval = PlayerPrefs.GetInt(TestKey.NormalToSpecailRestTaskInterval);
            var count = this.manager.GetTaskCount(TaskType.RestTask);
            if (count != 0 && count % interval == 0)
            {
                this.countDownSecond = PlayerPrefs.GetInt(TestKey.SpecailRestTask);
                isSet = true;
            }
        }
        if (!isSet)
        {
            this.countDownSecond = PlayerPrefs.GetInt(TestKey.NormalRestTask);
        }


        // 设置面板
        CountDownPanel.Instance.Reset();
        CountDownPanel.Instance.Open();
        CountDownPanel.Instance.SetCountDownTime(countDownSecond / 60, (int)countDownSecond % 60);
        CountDownPanel.Instance.SetFinishBtn(true, finishDelegate, "结束休息");
        CountDownPanel.Instance.SetFinishBtnPos(new Vector3(0,-770,0));

        BeginCountDown();
    }

    void OnClickFinish()
    {
        finishDelegate.oneShot = true;
        finishDelegate.Clear();
        this.Stop();
        this.customString = "  [手动结束休息]  ";
        state = TaskStateType.CurUtilFinish;
    }
}
